#include "Frm04.h"

Frm04::Frm04(HmiApp* app, STTWidget *par, const string& id, const string& desc) : STTPage(app->getRuntime(), par, id, desc) {
	hmiApp = app;
}

Frm04::~Frm04() {
}

void Frm04::onInit() {

}

void Frm04::createParts() {
	setMainArg(0, 0, 1024, 600);
	setMainStyle(0, 0xffffff, 0xffffff, 0, 255, 0, 0xc0c0c0);

	/*----------------------------- Spinner : wMSpinner1                 -----------------------------*/
	wMSpinner1 = new STTSpinner(p_rt, this, "wMSpinner1");
	wMSpinner1->setMainArg(271, 0, 100, 100);
	wMSpinner1->setMainStyle(20, 0xc0c0c0);
	wMSpinner1->setIndicStyle(20, 0x1a2b1);
	wMSpinner1->setRanges(0, 100, 0, 10);
	wMSpinner1->setAnim(60, 2000, false);

	/*----------------------------- Button : wMButton1                   -----------------------------*/
	wMButton1 = new STTButton(p_rt, this, "wMButton1", 0);
	wMButton1->setMainArg(133, 1, 98, 48, false);
	wMButton1->setPressedArg("停止", 0x0, "文泉驿微米黑", 16, 0);
	wMButton1->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton1->setReleasedArg("停止", 0x0, "文泉驿微米黑", 16, 0);
	wMButton1->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton1->onEventHandler(Event::CLICKED, this, (EHandler) & Frm04::wMButton1_clk_cb);

	/*----------------------------- Button : wMButton2                   -----------------------------*/
	wMButton2 = new STTButton(p_rt, this, "wMButton2", 0);
	wMButton2->setMainArg(133, 50, 98, 48, false);
	wMButton2->setPressedArg("转一圈", 0x0, "文泉驿微米黑", 16, 0);
	wMButton2->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton2->setReleasedArg("转一圈", 0x0, "文泉驿微米黑", 16, 0);
	wMButton2->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton2->onEventHandler(Event::CLICKED, this, (EHandler) & Frm04::wMButton2_clk_cb);

	/*----------------------------- Button : wMButton3                   -----------------------------*/
	wMButton3 = new STTButton(p_rt, this, "wMButton3", 0);
	wMButton3->setMainArg(133, 100, 98, 48, false);
	wMButton3->setPressedArg("无限转", 0x0, "文泉驿微米黑", 16, 0);
	wMButton3->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton3->setReleasedArg("无限转", 0x0, "文泉驿微米黑", 16, 0);
	wMButton3->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton3->onEventHandler(Event::CLICKED, this, (EHandler) & Frm04::wMButton3_clk_cb);

	/*----------------------------- Gauge : wMGauge1                     -----------------------------*/
	wMGauge1 = new STTMeter(p_rt, this, "wMGauge1");
	wMGauge1->setGaugeMainArg(24, 199, 120, 120, 80, 0, 100, 270, true, true, 1, 0, 5);
	wMGauge1->setGaugeMainStyle(9999, 0xffffff, 0xffffff, 0, 255, 2, 0x808080, 0, 0x0);
	wMGauge1->setGaugeNeedleStyle(0xff0000, 0, 2, NULL, 0, 3, 3, -4);
	wMGauge1->setGaugeFont(0x0, 12, "文泉驿微米黑", 0);
	wMGauge1->setGaugeTickStyle(0xff0000, 0xff, 0xff00ff, 2, 2, 8, 21);
	wMGauge1->setGaugeMajorTickStyle(2, 8, 6, 20);
	wMGauge1->setGaugeCircleStyle(9999, 0x0, 0xffffff, 0, 0, 0x0, 0, 0xffffff);

	/*----------------------------- Button : wMButton4                   -----------------------------*/
	wMButton4 = new STTButton(p_rt, this, "wMButton4", 0);
	wMButton4->setMainArg(1, 1, 98, 48, false);
	wMButton4->setPressedArg("返回主页", 0x0, "文泉驿微米黑", 16, 0);
	wMButton4->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton4->setReleasedArg("返回主页", 0x0, "文泉驿微米黑", 16, 0);
	wMButton4->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton4->bindOpenFormHandler(Event::CLICKED, "Frm03", PageMode::NEWWIN, NULL);

	/*called after widget created.*/

	return; //createParts END
}

void Frm04::onLoad() {
	wMGauge1->getStyle()->p_pad->setAll(0);
	wMGauge1->getStyle()->p_pad->setGap(0);
}

bool Frm04::onClosing() {
	return true;
}

void Frm04::onDispose() {

}

void Frm04::wMButton1_clk_cb(uint16_t code, LvEvent e) {
	/*wMButton1（停止）的点击事件*/
	wMSpinner1->stopAnim();
}
void Frm04::wMButton2_clk_cb(uint16_t code, LvEvent e) {
	/*wMButton2（转一圈）的点击事件*/
	int i = wMSpinner1->getCurrentAngle();
	wMSpinner1->setAnim(60, 2000, false, 1, i);

}

void Frm04::wMButton3_clk_cb(uint16_t code, LvEvent e) {
	/*wMButton3（无限转）的点击事件*/
	int i = wMSpinner1->getCurrentAngle();
	wMSpinner1->setAnim(60, 2000, false, -1, i);//-1无限

}
